﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using IHISCETeim.Library;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using IHISCETeim.Model;

namespace IHISCETeim.DAL
{
    public class SAPBorrowDAL
    {
        public static IDataReader SAPBorrow_GetList(int BrwID)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("SAPBorrow_GetList", BrwID);
            return DB.ExecuteReader(dbCommand);
        }
        public static DataTable SAPBorrow_GetPagination(string whereSql, int PageIndex, int PageSize, string Sort, ref int TotalCount)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("SAPBorrow_GetPagination");
            DB.AddInParameter(dbCommand, "whereSql", DbType.String, whereSql);
            DB.AddInParameter(dbCommand, "PageIndex", DbType.Int32, PageIndex);
            DB.AddInParameter(dbCommand, "PageSize", DbType.Int32, PageSize);
            DB.AddInParameter(dbCommand, "Sort", DbType.String, Sort);
            DB.AddOutParameter(dbCommand, "TotalCount", DbType.Int32, 8);
            DataTable dt = DB.ExecuteDataSet(dbCommand).Tables[0];

            TotalCount = Convert.ToInt32(DB.GetParameterValue(dbCommand, "TotalCount"));
            return dt;
        }
        public static int SAPBorrowReturn_Add(SAPBorrowReturnInfo obj)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("SAPBorrowReturn_Add");
            DB.AddInParameter(dbCommand, "BrwID", DbType.Int32, obj.BrwID);
            DB.AddInParameter(dbCommand, "GuHuanShiJian", DbType.DateTime, obj.GuHuanShiJian);
            DB.AddInParameter(dbCommand, "Quantity", DbType.Decimal, obj.Quantity);
            DB.AddInParameter(dbCommand, "CreateDate", DbType.DateTime, obj.CreateDate);
            DB.AddInParameter(dbCommand, "RealName", DbType.String, obj.RealName);
            DB.AddInParameter(dbCommand, "Remark", DbType.String, obj.Remark);

            //return Convert.ToInt32(DB.ExecuteScalar(dbCommand));
            return Convert.ToInt32(DB.ExecuteScalar(dbCommand));
        }
        public static IDataReader SAPBorrowReturn_GetAll(int BrwID)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("SAPBorrowReturn_GetAll", BrwID);
            return DB.ExecuteReader(dbCommand);
        }
    }
}
